import {Graph} from '@antv/g6';
import baseOption from './options'
import clickEvent from "./clickEvent.js";

let graphExample = null

//初始化图谱方法
class initGraph {
    constructor(config) {
        this.data = config.data
        this.width = config.width
        this.height = config.height
        this.container = config.container
        this.optionsConfig = config.optionsConfig
    }

    // 初始化图谱
    initGraph(callBack) {
        graphExample = new Graph({
            data: this.data,
            width: this.width,
            height: this.height,
            container: this.container,
            ...baseOption(this.optionsConfig)
        });
        graphExample.render().then(() => {
            callBack ? callBack(graphExample) : null
            const graphClickEvent = new clickEvent(graphExample, this.optionsConfig)
            graphClickEvent.init()
        });
    }
}

export {initGraph, graphExample}
